//package cn.tianyigps.tianyigpsapiv2.dao;
//
//import cn.tianyigps.tianyigpsapiv2.param.dto.EquipmentDTO;
//import cn.tianyigps.tianyigpsapiv2.utils.TimeUtil;
//import cn.tianyigps.tianyigpspublic.bean.EquipmentModel;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Sort;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.springframework.data.mongodb.core.query.Criteria;
//import org.springframework.data.mongodb.core.query.Query;
//import org.springframework.stereotype.Repository;
//
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//
//
///**
// * @Author: LiuHao
// * @Descirption:
// * @Date: 2019/4/19_14:09
// */
//@Repository
//public class EquipmentDao extends BaseDao<EquipmentModel> {
//
//    private static final String LOCUS_COLLECTION_PREFIX = "m7Equipment".concat("-");//轨迹表前缀
//    private static final String LATEST_COLLECTION_NAME = "m7LatestEquipmentData";//实时数据表名
//
//    @Autowired
//    private MongoTemplate mongoTemplate;
//
//    /**
//     * 查询当天指定时间到24点
//     * @param date
//     * @param equipmentId
//     * @return
//     */
//    public List<EquipmentModel> findByDayTo24AndEquipmentId(Date date, String equipmentId){
//        String collectionName = LOCUS_COLLECTION_PREFIX.concat(TimeUtil.formatString(date,new SimpleDateFormat("yyyy-MM-dd")));
//        Date night = TimeUtil.weeHours(date,24);
//        Query query = new Query();
//        query.addCriteria(Criteria.where("equipmentId").is(equipmentId));
//        query.addCriteria(Criteria.where("locateTime").gte(date).lte(night));
//        query.with(new Sort(Sort.Direction.ASC, "locateTime"));
//        return mongoTemplate.find(query,EquipmentModel.class,collectionName);
//    }
//
//    /**
//     * 查询当天0点到指定时间
//     * @param date
//     * @param equipmentId
//     * @return
//     */
//    public List<EquipmentModel> findBy0ToDayAndEquipmentId(Date date, String equipmentId){
//        String collectionName = LOCUS_COLLECTION_PREFIX.concat(TimeUtil.formatString(date,new SimpleDateFormat("yyyy-MM-dd")));
//        Date morning = TimeUtil.weeHours(date,0);
//        Query query = new Query();
//        query.addCriteria(Criteria.where("equipmentId").is(equipmentId));
//        query.addCriteria(Criteria.where("locateTime").gte(morning).lte(date));
//        query.with(new Sort(Sort.Direction.ASC, "locateTime"));
//        return mongoTemplate.find(query,EquipmentModel.class,collectionName);
//    }
//
//    public List<EquipmentModel> findByDaysAndEquipmentId(List<String> days, String equipmentId){
//        List result = new ArrayList();
//        days.stream().forEach(
//                day->{
//                    String collectionName = LOCUS_COLLECTION_PREFIX.concat(day);
//                    result.addAll(findByEquipmentId(equipmentId,collectionName));
//                }
//        );
//        return result;
//    }
//
//    private List<EquipmentModel> findByEquipmentId(String equipmentId, String collectionName){
//        Query query = new Query();
//        query.addCriteria(Criteria.where("equipmentId").is(equipmentId));
//        query.with(new Sort(Sort.Direction.ASC, "locateTime"));
//        return mongoTemplate.find(query,EquipmentModel.class,collectionName);
//    }
//
//}
